Test Series - Data Structure

Test Number 26/115

Q: What data structure is used when converting an infix notation to prefix notation?
A. Stack
B. Queue
C. B-Trees
D. Linked-list
Solution: First you reverse the given equation and carry out the algorithm of infix to postfix expression. Here, the data structure used is stacks.
Q: What would be the Prefix notation for the given equation?

A+(B*C)
A. +A*CB
B. *B+AC
C. +A*BC
D. *A+CB
Solution: Reverse the equation or scan the equation from right to left. Apply the infix-postfix algorithm. The equation inside the bracket evaluates to CB* and outside the bracket evaluates to A+ therefore getting CB*A+. Reversing this and we get +A*BC.
Q: What would be the Prefix notation for the given equation?

(A*B)+(C*D)
A. +*AB*CD
B. *+AB*CD
C. **AB+CD
D. +*BA*CD
Solution: Reverse the equation or scan the equation from right to left. Apply the infix-postfix algorithm. The equation inside the brackets evaluate to DC* and BA* respectively giving us DC*BA*+ in the end. Reversing this we get the +*AB*CD.
Q: What would be the Prefix notation for the given equation?

A+B*C^D
A. +A*B^CD
B. +A^B*CD
C. *A+B^CD
D. ^A*B+CD
Solution: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows +*^. Operators are pushed into the stack and popped if its preference is greater than the one which is getting pushed. In the end all operators are popped. The equation evaluates to DC^B*A+. Reversing this we get our following answer.
Q: Out of the following operators (^, *, +, &, $), the one having highest priority is _________
A. +
B. $
C. ^
D. &
Solution: According to the algorithm (infix-prefix), it follows that the exponentiation will have the highest priority.
Q: Out of the following operators (|, *, +, &, $), the one having lowest priority is ________
A. +
B. $
C. |
D. &
Solution: According to the algorithm (infix-prefix), it follows that the logical OR will have the lowest priority.
Q: What would be the Prefix notation for the given equation?

A^B^C^D
A. ^^^ABCD
B. ^A^B^CD
C. ABCD^^^
D. AB^C^D
Solution: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. Here we have to remember that the exponentiation has order of associativity from right to left. Therefore the stack goes on pushing ^. Therefore resulting in ^^^ABCD.
Q: What would be the Prefix notation for the given equation?

a+b-c/d&e|f
A. |&-+ab/cdef
B. &|-+ab/cdef
C. |&-ab+/cdef
D. |&-+/abcdef
Solution: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows |&+*/.
Q: What would be the Prefix notation for the given equation?

(a+(b/c)*(d^e)-f)
A. -+a*/^bcdef
B.  -+a*/bc^def
C. -+a*b/c^def
D. -a+*/bc^def
Solution: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows +*/^. Brackets have the highest priority. The equations inside the brackets are solved first.
Q: What would be the Prefix notation and Postfix notation for the given equation?

A+B+C
A. ++ABC and AB+C+
B. AB+C+ and ++ABC
C. ABC++ and AB+C+
D. ABC+ and ABC+
Solution: For prefix notation there is a need of reversing the giving equation and solving it as a normal infix-postfix question. We see that it doesn’t result as same as normal infix-postfix conversion.

You Have Score    /10